Skip to content

Conversation

@StillGreen-san
Copy link
Collaborator

this removes wrong GraphApiErrorException parsing logic and improves its fault tolerance

remove incorrect GraphApiError parsing

my previous implementation was wrong. the graph api error docs are a bit wage and i must have missed the link to the more detailed explanation. previously this could result in failure to create the exception.
now it only tries to parse the outer most required fields. the complete error object is additionally stored as a JSONObject. this greatly simplifies parsing and printing, which currently are the only use cases for this information anyway.

prevent exceptions during GraphApiErrorException creation

previously if there was an issue parsing the error response, an exception would be thrown, loosing the status code and cluttering the stack trace.
now it will always create the exception, simply noting a parsing failure in its message.

remove Response constructor from GraphApiErrorException

Response.body may return null and the exception would need to handle that.
the caller however, does most likely have context to determine if it would be null or not. potentially passing a custom json string that would provide more info than a generic 'was null'.
it also prevents potential double reads of the body, which are not supported.

use case-insensitive JSON parsing in GraphApiErrorException

the docs use inconsistent capitalization for the json keys. so this change was made to make parsing more tolerant in case this is real world behavior.
since case insensitive lookup may be something thats useful elsewhere, it was put in a separat JsonUtil file.

OneDrive cleanup

uploadToSession had become quite large, so i took the opportunity to move accept and error handling into separate functions

print output examples

invalid json:

- org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
+ ratismal.drivebackup.uploaders.onedrive.GraphApiErrorException: 123 invalidErrorResponse : "A JSONObject text must begin with '{' at 1 [character 2 line 1]"
- 	at org.json.JSONTokener.syntaxError(JSONTokener.java:503)
- 	at org.json.JSONObject.<init>(JSONObject.java:213)
- 	at org.json.JSONObject.<init>(JSONObject.java:430)
- 	at ratismal.drivebackup.uploaders.onedrive.GraphApiErrorException.<init>(GraphApiErrorException.java:59)
	at moe.sgs.Main.Try(Main.java:44)
	at moe.sgs.Main.main(Main.java:38)

with inner error:

- ratismal.drivebackup.uploaders.onedrive.GraphApiErrorException: 101 badRequest : "Uploaded fragment overlaps with existing data." inner:[ "invalidRange" ]
+ ratismal.drivebackup.uploaders.onedrive.GraphApiErrorException: 101 badRequest : "Uploaded fragment overlaps with existing data."
+ {
+   "code": "badRequest",
+   "innererror": {
+     "date": "date-time",
+     "code": "invalidRange",
+     "request-id": "request-id"
+   },
+   "message": "Uploaded fragment overlaps with existing data."
+ }
	at moe.sgs.Main.Try(Main.java:44)
	at moe.sgs.Main.main(Main.java:32)

@StillGreen-san
Copy link
Collaborator Author

not sure what to make of the ci error

@rhld16
Copy link
Collaborator

rhld16 commented Nov 18, 2025

Seemed to be some rogue jdk cdn error - all good now.
As it happens I’ve been working on an idea I had for this plugin recently (after over a year dormant lol). I’ll take a look at this as well and we can probably get a point release out soon. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants